<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\MessageService;
use Webman\Stomp\Client;

class BatchReceiverSendNotifyMessageConsumerV2 extends BaseConsumer
{

    // 要消费的队列名
    public $queue = 'batch_receiver_send_notify_message_v2';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * 消费
     * @param $data
     */
    public function doConsume($data)
    {
        $receiverList = $data['receiver'] ?? [];
        if (empty($receiverList)) {
            return;
        }
        try {
            APP_DEBUG && trace(var_export($data, true), 'DEBUG');
            foreach ($receiverList as $receiverItem) {
                $currentMessageData = $data;
                $currentMessageData['receiver'] = $receiverItem;
                Client::send('send_notify_message_v2', build_queue_data_with_xu($currentMessageData));
            }
        } catch (\Throwable $e) {
            trace(format_exception_info($e), "ERR");
        }
    }

}


